﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class StandartVariableExpressionElement : VariableExpressionElement
    {
        private ExpressionElement source;
        private List<PartOfStandartVariableExpressionElement> parts;

        public ExpressionElement Source { get { return source; } set { source = value; } }
        public List<PartOfStandartVariableExpressionElement> Parts { get { return parts; } set { parts = parts; } }

        public StandartVariableExpressionElement(TokenInfo StartInfo, ExpressionElement Source, List<PartOfStandartVariableExpressionElement> Parts, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            source = Source;
            parts = Parts;
        }

        public override string ToString()
        {
            string result = string.Empty;
            if (source != null)
            {
                result = string.Format("({0})", source);
                if ((parts != null) && (parts.Count > 0))
                    result += '.';
            }
            if (parts != null)
                result += parts.Join(".");
            return result;
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (source != null)
                yield return source;
            if (parts != null)
                foreach (PartOfStandartVariableExpressionElement part in parts)
                    yield return part;
        }
    }
}
